#include "wow.h"

#ifndef F_CPU
#define F_CPU 8000000UL
#endif

#include <avr/interrupt.h>
#include <util/delay.h>

volatile uint8_t wow;

ISR(WOW_VEC) {
  /* Ooops, got a change on WOW sensor */
  /* Sensor outputs low when on ground and high
     when airborne, so wow should be the negative
     of its value */
  wow = (PINB & 0b00000001);
  wow = (~wow) & 0b00000001;
}

void wow_init(void) {
  /* Set WOW pin as Input with enabled pull-up*/
  WOWPIN_DDR &= ~(1<<WOWPIN_NAME);
  WOWPIN_PORT |= (1<<WOWPIN_NAME);
  /* Set the Pin-Change Control Register */
  WOWREG |= (1<<WOWCONF);
  /* Enable Interrupts on WOWPIN */
  WOWMSK |= 1<<WOWPIN;
  /* You should be on the floor at this moment */
  wow = 1;
}

